<?php

namespace IMT\EventBundle\Models;

use Symfony\Component\HttpFoundation\Request;

use Symfony\Bundle\TwigBundle\TwigEngine;

use Symfony\Component\Security\Acl\Model\AclProviderInterface;
use Symfony\Component\Security\Core\SecurityContext;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Symfony\Component\Security\Acl\Domain\ObjectIdentity;
use Symfony\Component\Security\Acl\Domain\UserSecurityIdentity;
use Symfony\Component\Security\Acl\Permission\MaskBuilder;

abstract class EventManager implements EventManagerInterface
{
    // Services ...
	protected $aclProvider;
	protected $securityContext;
	protected $request;
	protected $templating;
	
	protected $plugins;
	
	protected $templatesBase;
	protected $type;
	
    /**
     * Constructor.
     */
    public function __construct(AclProviderInterface $aclProvider, SecurityContext $securityContext, Request $request, TwigEngine $templating, array $templatesBase)
    {
    	$this->plugins = array();
    	
    	$this->aclProvider = $aclProvider;
    	$this->securityContext = $securityContext;
    	$this->request = $request;
    	$this->templating = $templating;
    	
    	$this->templatesBase = $templatesBase;
    }
    
    /**
     * Conversion des données de config pour être lu en JSon directement par le plugin eventManager
     * 
     * @param array $config
     * @return json
     */
    public function convertConfigToJSON(array $config)
    {
    	// TODO: Vérifier la struture des paramètre en fonction des paramètres du plugin eventManager
    	return json_encode($config);
    }
	
    /**
     * {@inheritDoc}
     */
    public function createEvent()
    {
    	$class = $this->getClass();
    	$event = new $class;
    	
    	$this->hydrateEvent($event);
    
    	return $event;
    }
    
    public function addPlugins($plugin)
    {
    	$this->plugins[] = $plugin;
    }
    
    /**
     * {@inheritDoc}
     */
    public function getDefaultConfig()
    {
  		$config = array(
  			'templates' => array(
  				'base' => $this->templating->render($this->templatesBase['base']),
  				'error' => $this->templating->render($this->templatesBase['error'])		
  			),
  			'type' => $this->type	
  		);
  		
  		return $config;
    }
    
	/**
	 * @return the $templatesBase
	 */
	public function getTemplatesBase() {
		return $this->templatesBase;
	}

	/**
	 * @return the $type
	 */
	public function getType() {
		return $this->type;
	}

	/**
	 * @param multitype: $templatesBase
	 */
	public function setTemplatesBase($templatesBase) {
		$this->templatesBase = $templatesBase;
	}

	/**
	 * @param field_type $type
	 */
	public function setType($type) {
		$this->type = $type;
	}

    
    
}